package it.polimi.traveldream.web.beans.employee;

import it.polimi.traveldream.ejbclient.dtos.ExcursionDTO;

import it.polimi.traveldream.ejbclient.dtos.HotelDTO;
import it.polimi.traveldream.ejbclient.dtos.TransportDTO;
import it.polimi.traveldream.ejbclient.eaos.BaseProductServiceEAO;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.SelectEvent;

@ManagedBean(name="listBaseProducts")
@SessionScoped
public class ListBaseProducts {
	@EJB
	private BaseProductServiceEAO bService;
	private List<HotelDTO> hotels;
	private List<TransportDTO> transports;
	private List<ExcursionDTO> excursions;
	private HotelDTO selectedHotel;
	private TransportDTO selectedTransport;
	private ExcursionDTO selectedExcursion;
	@ManagedProperty(value="#{personalHomeEmployee}")
	private PersonalHomeEmployeeBean employeeBean;
	
	public ListBaseProducts() {
	}
	
	@PostConstruct
	public void init() {
		hotels = bService.getHotels(employeeBean.isBaseProductOverpast());
		transports = bService.getTransports(employeeBean.isBaseProductOverpast());
		excursions = bService.getExcursions(employeeBean.isBaseProductOverpast());
	}

	public void setEmployeeBean(PersonalHomeEmployeeBean employeeBean) {
		this.employeeBean = employeeBean;
	}

	public List<HotelDTO> getHotels() {
		return hotels;
	}
	
	public List<TransportDTO> getTransports() {
		return transports;
	}
	
	public List<ExcursionDTO> getExcursions() {
		return excursions;
	}

	public HotelDTO getSelectedHotel() {
		return selectedHotel;
	}

	public void setSelectedHotel(HotelDTO selectedHotel) {
		this.selectedHotel = selectedHotel;
	}
	
	public TransportDTO getSelectedTransport() {
		return selectedTransport;
	}

	public void setSelectedTransport(TransportDTO selectedTransport) {
		this.selectedTransport = selectedTransport;
	}

	public ExcursionDTO getSelectedExcursion() {
		return selectedExcursion;
	}

	public void setSelectedExcursion(ExcursionDTO selectedExcursion) {
		this.selectedExcursion = selectedExcursion;
	}

	public void onHotelRowSelectNavigate(SelectEvent event) {
		FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedHotel", event.getObject());  
		ConfigurableNavigationHandler nh = (ConfigurableNavigationHandler)FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
		nh.performNavigation("detailHotel?faces-redirect=true"); 
    }
	
	public void onTransportRowSelectNavigate(SelectEvent event) {
		FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedTransport", event.getObject());  
		ConfigurableNavigationHandler nh = (ConfigurableNavigationHandler)FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
		nh.performNavigation("detailTransport?faces-redirect=true"); 
    }
	
	public void onExcursionRowSelectNavigate(SelectEvent event) {
		FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedExcursion", event.getObject());  
		ConfigurableNavigationHandler nh = (ConfigurableNavigationHandler)FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
		nh.performNavigation("detailExcursion?faces-redirect=true"); 
    }
	
}
